package com.mission.schedule.newAdapter

import android.annotation.SuppressLint
import android.app.Service
import android.content.Context
import android.graphics.Color
import android.graphics.Paint
import android.os.Handler
import android.os.Message
import android.os.Vibrator
import android.support.v7.widget.RecyclerView
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.style.BackgroundColorSpan
import android.text.style.ForegroundColorSpan
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.widget.*
import com.mission.schedule.R
import com.mission.schedule.applcation.App
import com.mission.schedule.bean.CalenderNoteBean
import com.mission.schedule.constants.ShareFile
import com.mission.schedule.entity.CLCategoryTable
import com.mission.schedule.entity.CLRepeatTable
import com.mission.schedule.entity.ScheduleTable
import com.mission.schedule.my160920.bean.LyNewNumBean
import com.mission.schedule.utils.*
import com.mission.schedule.widget.SwipeLinearLayout
import kotlinx.android.synthetic.main.adapter_myrepeat.view.*
import kotlinx.android.synthetic.main.adapter_timeall_item_new1.view.*
import kotlinx.android.synthetic.main.adapter_timeall_item_new1.view.comename_tv
import kotlinx.android.synthetic.main.adapter_timeall_item_new1.view.delete_ll
import kotlinx.android.synthetic.main.adapter_timeall_item_new1.view.important_icon
import kotlinx.android.synthetic.main.adapter_timeall_item_new1.view.newcome_ll
import kotlinx.android.synthetic.main.adapter_timeall_item_new1.view.newcome_tv
import kotlinx.android.synthetic.main.adapter_timeall_item_new1.view.personstate_tv
import kotlinx.android.synthetic.main.adapter_timeall_item_new1.view.xcx_tv
import java.util.*
import kotlin.collections.ArrayList

/**
 * Created by liwei on 2018/1/23.
 */
class SchHeaderViewAdapter(context: Context, list: ArrayList<MutableMap<String, String>>, handler: Handler, uncount: Int, localpath: String) :
        RecyclerView.Adapter<RecyclerView.ViewHolder>() {

    var context = context
    var list = list

    var sharedPrefUtil: SharedPrefUtil? = null
    var userid = ""

    val handler: Handler = handler
    val localpath = localpath
    val uncount = uncount
    var swipeLinearLayouts = arrayListOf<SwipeLinearLayout>()
    val listBeanList = ArrayList<LyNewNumBean.ListBean>()

    init {
        sharedPrefUtil = SharedPrefUtil(context, ShareFile.USERFILE)
        userid = sharedPrefUtil!!.getString(context, ShareFile.USERFILE, ShareFile.USERID, "")
    }

    private fun setOnclick(positions: Int, map: Map<String, String>, what: Int, type: Int) {
        val message = Message.obtain()
        message.arg1 = positions
        message.arg2 = type
        message.obj = map
        message.what = what
        handler.sendMessage(message)
    }

    override fun getItemCount(): Int = list.size
    inner class Holder(view: View) : RecyclerView.ViewHolder(view)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.adapter_timeall_item_new1, parent, false)
        return Holder(view)
    }

    fun setNewState(listBean: List<LyNewNumBean.ListBean>) {
        listBeanList.clear()
        listBeanList.addAll(listBean)
        notifyDataSetChanged()
    }

    open fun deleteCaledner(position: Int) {
        notifyItemRemoved(position)
        notifyItemRangeRemoved(position, list.size)
    }

    open fun addCalender(position: Int) {
        notifyItemRangeChanged(0, list.size, 1)
    }

    open fun updateCalender(position: Int, map: MutableMap<String, String>) {
        list[position] = map
        notifyItemRangeChanged(position, list.size, 1)
    }

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        var mMap = list[holder.adapterPosition]
        swipeLinearLayouts.add(holder.itemView.sch_sl)
        val holder = holder as Holder
        holder.itemView.sch_sl.setOnSwipeListener { thisSll, isholderrizontal ->
            if (!isholderrizontal) {
                swipeLinearLayouts
                        .forEach { it.scrollAuto(SwipeLinearLayout.DIRECTION_SHRINK) }
            } else {
                swipeLinearLayouts
                        .filter { it != thisSll }
                        .forEach {
                            //划开一个sll， 其他收缩
                            it.scrollAuto(SwipeLinearLayout.DIRECTION_SHRINK)
                        }
            }
        }

        val timeall_rela_right = holder.itemView.timeall_rela_right // 下面整体布局
        val timeall_tv_time = holder.itemView.timeall_tv_time // 时间
        // 如：全天或08：00
        val timeall_tv_shun = holder.itemView.timeall_tv_shun // 顺延
        // 如：顺
        val timeall_tv_lastday = holder.itemView.timeall_tv_lastday // 多少小时后，多少天后
        val timeall_tv_content = holder.itemView.timeall_tv_content // 日程内容
        // TextView timeall_tv_has = holder.getView(R.id.timeall_tv_has); //
        // 标题栏天后
        val personstate_tv = holder.itemView.personstate_tv// 公开状态
        val tv_delete = holder.itemView.tv_delete// 删除
        val tv_more = holder.itemView.ll_more// 更多
        val more_ll = holder.itemView.delete_ll// 侧滑
        val guoqi_img = holder.itemView.guoqi_img// 过期未结束图标，在今天中才显示
        val comename_tv = holder.itemView.comename_tv// 来自谁的日程
        val select_cb = holder.itemView.select_cb
        val bottom_month = holder.itemView.bottom_month
        val bottom_week = holder.itemView.bottom_week
        val select_cb_ll = holder.itemView.select_cb_ll
        val newcome_ll = holder.itemView.newcome_ll
        val newcome_tv = holder.itemView.newcome_tv
        val important_icon = holder.itemView.important_icon
        val new_img = holder.itemView.new_img
        val xcx_tv = holder.itemView.xcx_tv

        timeall_rela_right.setOnClickListener {
            // 点击详情菜单
            holder.itemView.sch_sl.scrollAuto(SwipeLinearLayout.DIRECTION_SHRINK)
            setOnclick(holder.adapterPosition, mMap, 0, 2)
        }
        timeall_rela_right.setOnLongClickListener {
//            val vib = context.getSystemService(Service.VIBRATOR_SERVICE) as Vibrator
//            val pattern = longArrayOf(1000, 2000)
//            vib.vibrate(pattern, 1)

            holder.itemView.sch_sl.scrollAuto(SwipeLinearLayout.DIRECTION_SHRINK)
            setOnclick(holder.adapterPosition, mMap, -2, 2)
            false
        }

        timeall_rela_right.setOnTouchListener { v, event ->
            if (event.action == MotionEvent.ACTION_DOWN) {
//                Toast.makeText(context, "${timeall_rela_right.measuredHeight}  ${event.y}", Toast.LENGTH_SHORT).show()
                App.get(context).pointX = event.x
                App.get(context).pointY = event.y
                App.get(context).viewH = timeall_rela_right.measuredHeight.toFloat()
                App.get(context).rawY = event.rawY
                App.get(context).pointV = v
            }
            false
        }

        tv_delete.setOnClickListener {
            holder.itemView.sch_sl.scrollAuto(SwipeLinearLayout.DIRECTION_SHRINK)
            // 右滑删除
            setOnclick(holder.adapterPosition, mMap, 3, 2)
        }
//        holder.itemView.ll_more.setOnClickListener {
//            holder.itemView.sch_sl.scrollAuto(SwipeLinearLayout.DIRECTION_SHRINK)
//            // 右滑更多
//            setOnclick(holder.adapterPosition, mMap, 7, 2)
//        }
        select_cb_ll.setOnClickListener {
            // 选中表示结束
            if (select_cb.isChecked) {
                setOnclick(holder.adapterPosition, mMap, 2, 2)
            } else {
                setOnclick(holder.adapterPosition, mMap, 2, 3)
            }
        }

        select_cb.setOnClickListener {
            // 选中表示结束
            if (select_cb.isChecked) {
                setOnclick(holder.adapterPosition, mMap, 2, 2)
            } else {
                setOnclick(holder.adapterPosition, mMap, 2, 3)
            }
        }

        val displayAlarm = mMap[ScheduleTable.schDisplayTime]
        val postpone = mMap[ScheduleTable.schIsPostpone]
        val alarmClockTime = mMap[ScheduleTable.schTime]
        val isEnd = mMap[ScheduleTable.schIsEnd]
        val beforTime = Integer.parseInt(mMap[ScheduleTable.schBeforeTime])
        val important = mMap[ScheduleTable.schIsImportant]

        val calendar = Calendar.getInstance()
        calendar.time = Date()
        var today = DateUtil.formatDateTime(calendar.time)
        calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + 1)
        var tomorrow = DateUtil.formatDateTime(calendar.time)
        calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + 7)
        var inweek = DateUtil.formatDateTime(calendar.time)


        val schContentschRemark12 = mMap[ScheduleTable.schContent] + (if (mMap[ScheduleTable.schRemark12] == null) "" else mMap[ScheduleTable.schRemark12])
        val key = mMap[ScheduleTable.schDate]
        val timeKey = mMap[ScheduleTable.schTime]

        val dateStr = DateUtil.parseDateTime("$key $timeKey")
        val ymd = key!!.split("-".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()

        var clockTime = ""
        var point = ""
        val point2 = ""
        var sequence = ""
        var shunBackKuang = 0
        var colorState = "#2ea9a4"
        var colorState2 = "#2ea9a4"
        var beforeStr = ""

        beforeStr = when (beforTime) {
            0 -> "0"
            5 -> "-5"
            15 -> "-15"
            30 -> "-30"
            60 -> "-1h"
            120 -> "-2h"
            1440 -> "-1d"
            2 * 1440 -> "-2d"
            3 * 1440 -> "-3d"
            5 * 1440 -> "-5d"
            7 * 1440 -> "-1w"
            15 * 1440 -> "-3w"
            else -> "0"
        }

        if ("1" == isEnd) {
            colorState = "#7F7F7F"// "#9f9f9f";
            colorState2 = "#7F7F7F"
            shunBackKuang = R.drawable.tv_kuang_before
        } else {
            colorState = when (key) {
                today.substring(0, 10) -> "" + context.resources.getColor(R.color.mingtian_color)
                tomorrow.substring(0, 10) -> "" + context.resources.getColor(R.color.mingtian_color)
                else -> "" + context.resources.getColor(R.color.mingtian_color)
            }
            colorState2 = colorState
            val date1 = DateUtil.parseDateTime(DateUtil.formatDateTime(Date()))
            if (dateStr!!.time < date1!!.time) {
                colorState = "" + context.resources.getColor(R.color.bg_red)
            }

            shunBackKuang = R.drawable.tv_kuang_aftertime
        }
        clockTime = if (beforeStr == "0") {
            ("<font color='" + colorState + "' size='5px'>"
                    + alarmClockTime + "</font>")
        } else {
            ("<font color='" + colorState + "' size='5px'>"
                    + alarmClockTime + "(" + beforeStr + ")" + "</font>")
        }
        // 全天
        point = ("<font color='" + colorState2 + "' size='5px'>"
                + context.getString(R.string.adapter_allday) + "</font>")
        // 顺延
        sequence = "<font color='" + colorState + "'>" + context.getString(R.string.adapter_shun) + "</font>"

        timeall_tv_content.text = if (schContentschRemark12.length > 2 && schContentschRemark12.substring(0, 2) == "#%")
            schContentschRemark12.substring(2, schContentschRemark12.length)
        else
            schContentschRemark12
        if ("1" == isEnd) {
            timeall_tv_content.setTextColor(Color.parseColor(colorState))
            timeall_tv_time.setTextColor(Color.parseColor(colorState))
            bottom_month.setTextColor(Color.parseColor(colorState))
            bottom_week.setTextColor(Color.parseColor(colorState))
            timeall_tv_content.paint.flags = Paint.STRIKE_THRU_TEXT_FLAG or Paint.ANTI_ALIAS_FLAG
        } else {
            timeall_tv_time.setTextColor(context.resources.getColor(R.color.mingtian_color))
            bottom_month.setTextColor(context.resources.getColor(R.color.mingtian_color))
            bottom_week.setTextColor(context.resources.getColor(R.color.mingtian_color))
            timeall_tv_content.setTextColor(Color.BLACK)
            timeall_tv_content.paint.flags = 0 or Paint.ANTI_ALIAS_FLAG
        }

        val openState = mMap[ScheduleTable.schOpenState]
        personstate_tv.visibility = View.GONE
        when (openState) {
            "0" -> personstate_tv.text = ""
            "1" -> personstate_tv.text = "公开"
            else -> personstate_tv.text = ""
        }

        if ("0" == mMap[ScheduleTable.schColorType]) {
            personstate_tv.visibility = View.GONE
        } else {
            if ("" != mMap[ScheduleTable.schColorType]) {
                val tagname = App.getDBcApplication().QueryTagNameData(
                        Integer.parseInt(mMap[ScheduleTable.schColorType]))!![CLCategoryTable.ctgText]
                if ("未分类" == tagname) {
                    personstate_tv.visibility = View.GONE
                } else {
                    personstate_tv.visibility = View.VISIBLE
                }
                personstate_tv.text = tagname
            }
        }

        val calendar1 = Calendar.getInstance()
        calendar1.time = DateUtil.parseDate(mMap[ScheduleTable.schDate])

        val dateToday = DateUtil.parseDateTime(DateUtil.formatDateTime(Date()))
        val betweem = (dateToday!!.time - dateStr.time) / 1000
        val day = betweem / (24 * 3600)
        val hour = betweem % (24 * 3600) / 3600
        val min = betweem % 3600 / 60
        val afterday = (DateUtil.parseDate(DateUtil.formatDate(Date()))!!.time - DateUtil.parseDate(key)!!.time) / 1000 / (24 * 3600)
        if (Integer.valueOf(mMap[ScheduleTable.schcRecommendId]) == -2) {
            comename_tv.visibility = View.VISIBLE
            comename_tv.text = "来自网页输入"
            comename_tv.setTextColor(Color.parseColor("#aaaaaa"))
        }
        bottom_month.visibility = View.GONE
        bottom_week.visibility = View.GONE

        guoqi_img.visibility = View.GONE
        timeall_tv_shun.visibility = View.GONE
        timeall_tv_lastday.visibility = View.GONE
        bottom_month.visibility = View.GONE
        bottom_week.visibility = View.GONE
        timeall_tv_time.text = context.getString(R.string.adapter_untask)
        timeall_tv_time.setTextAppearance(context, R.style.text_style_normal)
        timeall_tv_time.setTextColor(context.resources.getColor(R.color.gongkai_txt))


        val timeparams = LinearLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT)
        if (bottom_month.visibility == View.VISIBLE) {
            timeparams.setMargins(Utils.dipTopx(context, 5f), 0, 0, 0)
            timeall_tv_time.layoutParams = timeparams
        }
        important_icon.visibility = View.GONE
        if ("1" == isEnd) {
            select_cb.isChecked = true
            if ("1" == mMap[ScheduleTable.schIsImportant]) {
                timeall_rela_right.background = context.resources.getDrawable(R.drawable.bg_sch_end)
                important_icon.visibility = View.VISIBLE
                important_icon.background = context.resources.getDrawable(R.mipmap.icon_zhongyao1)
            } else {
                important_icon.visibility = View.GONE
                timeall_rela_right.background = context.resources.getDrawable(R.drawable.bg_sch_end)
            }
            comename_tv.setTextColor(context.resources.getColor(R.color.gongkai_txt))
            if ("0" != StringUtils.getIsStringEqulesNull(mMap[ScheduleTable.schcRecommendId])) {
                if ("" != StringUtils.getIsStringEqulesNull(mMap[ScheduleTable.schcRecommendName]) && StringUtils.getIsStringEqulesNull(mMap[ScheduleTable.schcRecommendName]) != "到期日") {
                    comename_tv.visibility = View.GONE
                    timeall_tv_lastday.visibility = View.GONE
                    if (mMap[ScheduleTable.schSourceDesc]!!.isEmpty()) {
                        var new_type = false
                        for (i in listBeanList.indices) {
                            val cid = listBeanList[i].getCId().trim { it <= ' ' }
                            val schid = list[holder.adapterPosition][ScheduleTable.schID]!!.trim { it <= ' ' }
                            if (cid == schid && listBeanList[i].getCount() == 1) {
                                new_type = true
                                break
                            }
                        }
                        new_img.background = context.resources.getDrawable(R.mipmap.icon_diandian)
                        new_img.visibility = if (new_type == true) View.VISIBLE else View.GONE

                        val co = "@" + mMap[ScheduleTable.schcRecommendName] + ":"
                        val cb = co + (if (schContentschRemark12.length > 2 && schContentschRemark12.substring(0, 2) == "#%")
                            schContentschRemark12.substring(2, schContentschRemark12.length)
                        else
                            schContentschRemark12)
                        val style = SpannableStringBuilder(cb)
                        style.setSpan(ForegroundColorSpan(context.resources.getColor(R.color.gongkai_txt)), 0, co.length,
                                Spannable.SPAN_EXCLUSIVE_INCLUSIVE) //设置指定位置文字的颜色
                        timeall_tv_content.text = style
                    } else {
                        if (mMap[ScheduleTable.schRead] == "1" || mMap[ScheduleTable.schRead] == "-1") {
                            guoqi_img.visibility = View.VISIBLE
                        } else {
                            guoqi_img.visibility = View.GONE
                        }
                        var nums = App.getDBcApplication().getCalenderNoteData(mMap[ScheduleTable.schSourceDesc])
                        nums = if (nums != "0" && !nums.isEmpty()) {
                            "($nums)"
                        } else {
                            ""
                        }
                        val co: String
                        var schcRecommen = mMap[ScheduleTable.schTags]
                        timeall_tv_content.setTextColor(context.resources.getColor(R.color.gongkai_txt))
                        timeall_tv_content.text = ""
                        val name = if (mMap[ScheduleTable.schcRecommendId] == userid) "" else "@" + mMap[ScheduleTable.schcRecommendName]

                        if (!schcRecommen!!.isEmpty()) {
                            schcRecommen = if (schcRecommen == name) {
                                ""
                            } else {
                                " $schcRecommen"
                            }
                        }
                        if (mMap[ScheduleTable.schcRecommendId] == userid) {
                            schcRecommen = ""
                        }
                        co = name + nums + schcRecommen
                        if (!schContentschRemark12.isEmpty()) {
                            var content1 = schContentschRemark12
                            if (schContentschRemark12.length > 25) {
                                content1 = schContentschRemark12.substring(0, 25)
                            }
                            content1 = if (content1!!.length > 2 && content1!!.substring(0, 2) == "#%")
                                content1!!.substring(2, content1!!.length)
                            else
                                content1
                            val content = if (mMap[ScheduleTable.schcRecommendId] == userid) "#$content1#" else "#" + content1
                            val style = SpannableStringBuilder(content)
                            style.setSpan(ForegroundColorSpan(context.resources.getColor(R.color.blue)), 0, content.length,
                                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) //设置指定位置文字的颜色

                            timeall_tv_content.append(style)

                            val style1 = SpannableStringBuilder(co)
                            style1.setSpan(ForegroundColorSpan(context.resources.getColor(R.color.gongkai_txt)), 0, co.length,
                                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) //设置指定位置文字的颜色

                            timeall_tv_content.append(style1)
                        }
                    }

                    if ("1" == isEnd) {
                        val style = SpannableStringBuilder(timeall_tv_content.text.toString())
                        style.setSpan(ForegroundColorSpan(context.resources.getColor(R.color.endtextcolor)), 0, timeall_tv_content.text.toString().length,
                                Spannable.SPAN_EXCLUSIVE_INCLUSIVE) //设置指定位置文字的颜色
                        timeall_tv_content.text = style
                    }
                } else {
                    if ("0" != mMap[ScheduleTable.schRepeatID]) {
                        val type = App.getDBcApplication().queryRepateType(mMap[ScheduleTable.schRepeatID])["type"]
                        if ("0" == mMap[ScheduleTable.schRepeatLink]) {
                            comename_tv.visibility = View.GONE
                        } else {
                            comename_tv.visibility = View.VISIBLE
                            new_img.visibility = View.GONE
                        }
                        comename_tv.setTextColor(context.resources.getColor(R.color.gongkai_txt))
                        val repeatDate = if (mMap[ScheduleTable.schRepeatDate]!!.length > 10)
                            mMap[ScheduleTable.schRepeatDate]!!.substring(5, 10)
                        else
                            ""
                        if ("1" == type) {
                            comename_tv.text = "每天重复 $repeatDate"
                            color = "0"
                        } else if ("2" == type) {
                            comename_tv.text = "每周重复 $repeatDate"
                            color = sharedPrefUtil!!.getString(context, ShareFile.USERFILE, ShareFile.WEEKCOLOR1, "4")
                        } else if ("3" == type) {
                            comename_tv.text = "每月重复 $repeatDate"
                            color = sharedPrefUtil!!.getString(context, ShareFile.USERFILE, ShareFile.MONTHCOLOR2, "3")
                        } else if ("4" == type || "6" == type) {
                            comename_tv.text = "每年重复 $repeatDate"
                            color = sharedPrefUtil!!.getString(context, ShareFile.USERFILE, ShareFile.YEARCOLOR3, "2")
                        } else if ("5" == type) {
                            comename_tv.text = "工作日重复 $repeatDate"
                            color = "0"
                        } else {
                            App.getDBcApplication().deleteScheduleData(mMap[ScheduleTable.schID])
                        }
                        if ("1" == important) {
                            important_icon.visibility = View.VISIBLE
                            important_icon.background = context.resources.getDrawable(R.mipmap.icon_zhongyao1)
                        } else {
                            important_icon.visibility = View.GONE
                        }
                    } else {
                        comename_tv.visibility = View.GONE
                    }
                }
            } else if ("0" != mMap[ScheduleTable.schRepeatID]) {
                val type = App.getDBcApplication().queryRepateType(mMap[ScheduleTable.schRepeatID])["type"]
                if ("0" == mMap[ScheduleTable.schRepeatLink]) {
                    comename_tv.visibility = View.GONE
                } else {
                    comename_tv.visibility = View.VISIBLE
                    new_img.visibility = View.GONE
                }
                val repeatDate = if (mMap[ScheduleTable.schRepeatDate]!!.length > 10)
                    mMap[ScheduleTable.schRepeatDate]!!.substring(5, 10)
                else
                    ""
                if ("1" == type) {
                    comename_tv.text = "每天重复 " + repeatDate
                    color = "0"
                } else if ("2" == type) {
                    comename_tv.text = "每周重复 " + repeatDate
                    color = sharedPrefUtil!!.getString(context, ShareFile.USERFILE, ShareFile.WEEKCOLOR1, "4")
                } else if ("3" == type) {
                    comename_tv.text = "每月重复 " + repeatDate
                    color = sharedPrefUtil!!.getString(context, ShareFile.USERFILE, ShareFile.MONTHCOLOR2, "3")
                } else if ("4" == type || "6" == type) {
                    comename_tv.text = "每年重复 " + repeatDate
                    color = sharedPrefUtil!!.getString(context, ShareFile.USERFILE, ShareFile.YEARCOLOR3, "2")
                } else if ("5" == type) {
                    comename_tv.text = "工作日重复 " + repeatDate
                    color = "0"
                } else {
                    App.getDBcApplication().deleteScheduleData(mMap[ScheduleTable.schID])
                }
                if ("1" == important) {
                    important_icon.visibility = View.VISIBLE
                    important_icon.background = context.resources.getDrawable(R.mipmap.icon_zhongyao1)
                } else {
                    important_icon.visibility = View.GONE
                }
            }
            if ("2" == mMap[ScheduleTable.schSourceType]) {
                timeall_tv_content.text = if (schContentschRemark12.length > 2 && schContentschRemark12.substring(0, 2) == "#%")
                    schContentschRemark12.substring(2, schContentschRemark12.length)
                else
                    schContentschRemark12
                val list = App.getDBcApplication().getCalenderNoteDetailData(userid, mMap[ScheduleTable.schSourceDesc], false)

                val nums: String

                if (list.size > 0) {
                    nums = when {
                        list[0].style == 0 -> {
                            val endstate = list.count { it.endstate == 1 }
                            "(" + endstate + "/" + list.size + ")"
                        }
                        list[0].style == 4 -> "(" + nums(list[0].style, list) + ")"
                        else -> "(" + list.size + ")"
                    }

                    val style1 = SpannableStringBuilder(nums)
                    style1.setSpan(ForegroundColorSpan(context.resources.getColor(R.color.gongkai_txt)), 0, nums.length,
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) //设置指定位置文字的颜色

                    timeall_tv_content.append(style1)

                    if ("1" == isEnd) {
                        val style = SpannableStringBuilder(timeall_tv_content.text)
                        style.setSpan(ForegroundColorSpan(context.resources.getColor(R.color.endtextcolor)), 0, timeall_tv_content.text.length,
                                Spannable.SPAN_EXCLUSIVE_INCLUSIVE) //设置指定位置文字的颜色
                        timeall_tv_content.text = style
                    }
                }
            } else if ("3" == mMap[ScheduleTable.schSourceType] || "4" == mMap[ScheduleTable.schSourceType] || "5" == mMap[ScheduleTable.schSourceType]) {
                timeall_tv_content.text = if (schContentschRemark12.length > 2 && schContentschRemark12.substring(0, 2) == "#%")
                    schContentschRemark12.substring(2, schContentschRemark12.length)
                else
                    schContentschRemark12
                if ("3" == mMap[ScheduleTable.schSourceType]) {
                    timeall_tv_content.setTextColor(context.resources.getColor(R.color.Saturdaybackcolor))
                } else {
                    timeall_tv_content.setTextColor(context.resources.getColor(R.color.blue))
                }
                var nums = App.getDBcApplication().getCalenderNoteData(mMap[ScheduleTable.schSourceDesc])
                nums = if (nums != "0" && !nums.isEmpty()) {
                    "($nums)"
                } else {
                    ""
                }
                val style1 = SpannableStringBuilder(nums)
                style1.setSpan(ForegroundColorSpan(context.resources.getColor(R.color.gongkai_txt)), 0, nums.length,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) //设置指定位置文字的颜色
                timeall_tv_content.append(style1)
                if (mMap[ScheduleTable.schcRecommendName]!!.isNotEmpty() && mMap[ScheduleTable.schcRecommendId]!!.isNotEmpty()) {
                    comename_tv.visibility = View.VISIBLE
                    comename_tv.text = "@" + mMap[ScheduleTable.schcRecommendName]
                }
                comename_tv.setTextColor(context.resources.getColor(R.color.gongkai_txt))
                if (isEnd == "1") {
                    timeall_tv_content.setTextColor(Color.parseColor(colorState))
                    timeall_tv_time.setTextColor(Color.parseColor(colorState))
                    bottom_month.setTextColor(Color.parseColor(colorState))
                    bottom_week.setTextColor(Color.parseColor(colorState))
                    timeall_tv_content.paint.flags = Paint.STRIKE_THRU_TEXT_FLAG or Paint.ANTI_ALIAS_FLAG
                }
            }

            if (Integer.valueOf(mMap[ScheduleTable.schcRecommendId]) < 0 && mMap[ScheduleTable.schcRecommendName]!!.isEmpty()) {
                comename_tv.visibility = View.VISIBLE
                comename_tv.text = "到期日"
            }
            if (Integer.valueOf(mMap[ScheduleTable.schcRecommendId]) == -2) {
                comename_tv.visibility = View.VISIBLE
                comename_tv.text = "来自网页输入"
                comename_tv.setTextColor(Color.parseColor("#aaaaaa"))
            }
        } else {
            if ("1" == important) {
                important_icon.visibility = View.VISIBLE
                important_icon.background = context.resources.getDrawable(R.mipmap.icon_zhongyao)
            } else {
                important_icon.visibility = View.GONE
            }
            timeall_rela_right.background = context.resources.getDrawable(R.drawable.bg_sch_normal)
            select_cb.isChecked = false

            if ("0" != StringUtils.getIsStringEqulesNull(mMap[ScheduleTable.schcRecommendId])) {
                if ("" != StringUtils.getIsStringEqulesNull(mMap[ScheduleTable.schcRecommendName]) && StringUtils.getIsStringEqulesNull(mMap[ScheduleTable.schcRecommendName]) != "到期日") {
                    comename_tv.visibility = View.GONE
                    timeall_tv_lastday.visibility = View.GONE
                    if (mMap[ScheduleTable.schSourceDesc]!!.isEmpty()) {
                        var new_type = false
                        for (i in listBeanList.indices) {
                            val cid = listBeanList[i].getCId().trim({ it <= ' ' })
                            val schid = list[holder.adapterPosition][ScheduleTable.schID]!!.trim({ it <= ' ' })
                            if (cid == schid && listBeanList[i].getCount() == 1) {
                                new_type = true
                                break
                            }
                        }
                        new_img.background = context.resources.getDrawable(R.mipmap.icon_diandian)
                        new_img.visibility = if (new_type == true) View.VISIBLE else View.GONE
                        val co = "@" + mMap[ScheduleTable.schcRecommendName] + ":"
                        val cb = co + (if (schContentschRemark12.length > 2 && schContentschRemark12.substring(0, 2) == "#%")
                            schContentschRemark12.substring(2, schContentschRemark12.length)
                        else
                            schContentschRemark12)
                        val style = SpannableStringBuilder(cb)
                        style.setSpan(ForegroundColorSpan(context.resources.getColor(R.color.mingtian_color)), 0, co.length,
                                Spannable.SPAN_EXCLUSIVE_INCLUSIVE) //设置指定位置文字的颜色
                        timeall_tv_content.text = style
                    } else {
                        if (mMap[ScheduleTable.schRead] == "1" || mMap[ScheduleTable.schRead] == "-1") {
                            guoqi_img.visibility = View.VISIBLE
                        } else {
                            guoqi_img.visibility = View.GONE
                        }
                        var nums = App.getDBcApplication().getCalenderNoteData(mMap[ScheduleTable.schSourceDesc])
                        nums = if (nums != "0" && !nums.isEmpty()) {
                            "($nums)"
                        } else {
                            ""
                        }
                        val co: String
                        var schcRecommen = mMap[ScheduleTable.schTags]
                        timeall_tv_content.setTextColor(context.resources.getColor(R.color.gongkai_txt))
                        timeall_tv_content.text = ""
                        val name = if (mMap[ScheduleTable.schcRecommendId] == userid) "" else "@" + mMap[ScheduleTable.schcRecommendName]
                        if (!schcRecommen!!.isEmpty()) {
                            schcRecommen = if (schcRecommen == name) {
                                ""
                            } else {
                                " " + schcRecommen
                            }
                        }
                        if (mMap[ScheduleTable.schcRecommendId] == userid) {
                            schcRecommen = ""
                        }
                        co = name + nums + schcRecommen
                        if (!schContentschRemark12.isEmpty()) {
                            var content1 = schContentschRemark12
                            if (schContentschRemark12.length > 25) {
                                content1 = schContentschRemark12.substring(0, 25)
                            }
                            content1 = if (content1!!.length > 2 && content1!!.substring(0, 2) == "#%")
                                content1!!.substring(2, content1!!.length)
                            else
                                content1
                            val content = if (mMap[ScheduleTable.schcRecommendId] == userid) "#$content1#" else "#" + content1
                            val style = SpannableStringBuilder(content)
                            style.setSpan(ForegroundColorSpan(context.resources.getColor(R.color.blue)), 0, content.length,
                                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) //设置指定位置文字的颜色

                            timeall_tv_content.append(style)

                            val style1 = SpannableStringBuilder(co)
                            style1.setSpan(ForegroundColorSpan(context.resources.getColor(R.color.gongkai_txt)), 0, co.length,
                                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) //设置指定位置文字的颜色

                            timeall_tv_content.append(style1)
                        }
                    }

                    if ("1" == isEnd) {
                        val style = SpannableStringBuilder(timeall_tv_content.getText().toString())
                        style.setSpan(ForegroundColorSpan(context.resources.getColor(R.color.endtextcolor)), 0, timeall_tv_content.getText().toString().length,
                                Spannable.SPAN_EXCLUSIVE_INCLUSIVE) //设置指定位置文字的颜色
                        timeall_tv_content.text = style
                    }

                } else {
                    if ("0" != mMap[ScheduleTable.schRepeatID]) {
                        val type = App.getDBcApplication().queryRepateType(
                                mMap[ScheduleTable.schRepeatID])["type"]
                        if ("0" == mMap[ScheduleTable.schRepeatLink]) {
                            comename_tv.visibility = View.GONE
                        } else {
                            comename_tv.visibility = View.VISIBLE
                            new_img.visibility = View.GONE
                        }
                        comename_tv.setTextColor(context.resources
                                .getColor(R.color.gongkai_txt))
                        val repeatDate = if (mMap[ScheduleTable.schRepeatDate]!!.length > 10)
                            mMap[ScheduleTable.schRepeatDate]!!.substring(5, 10)
                        else
                            ""
                        if ("1" == type) {
                            comename_tv.text = "每天重复 $repeatDate"
                            color = "0"
                        } else if ("2" == type) {
                            comename_tv.text = "每周重复 $repeatDate"
                            color = sharedPrefUtil!!.getString(context, ShareFile.USERFILE, ShareFile.WEEKCOLOR1, "4")
                        } else if ("3" == type) {
                            comename_tv.text = "每月重复 $repeatDate"
                            color = sharedPrefUtil!!.getString(context, ShareFile.USERFILE, ShareFile.MONTHCOLOR2, "3")
                        } else if ("4" == type || "6" == type) {
                            comename_tv.text = "每年重复 $repeatDate"
                            color = sharedPrefUtil!!.getString(context, ShareFile.USERFILE, ShareFile.YEARCOLOR3, "2")
                        } else if ("5" == type) {
                            comename_tv.text = "工作日重复 $repeatDate"
                            color = "0"
                        } else {
                            App.getDBcApplication().deleteScheduleData(mMap[ScheduleTable.schID])
                        }
                        setBGcolor(timeall_rela_right, color)
                    } else {
                        comename_tv.visibility = View.GONE
                    }
                }
            } else {
                if ("0" != mMap[ScheduleTable.schRepeatID]) {
                    val type = App
                            .getDBcApplication()
                            .queryRepateType(mMap[ScheduleTable.schRepeatID])["type"]
                    if ("0" == mMap[ScheduleTable.schRepeatLink]) {
                        comename_tv.visibility = View.GONE
                    } else {
                        comename_tv.visibility = View.VISIBLE
                        new_img.visibility = View.GONE
                    }
                    comename_tv.setTextColor(context.resources.getColor(R.color.gongkai_txt))
                    val repeatDate = if (mMap[ScheduleTable.schRepeatDate]!!.length > 10)
                        mMap[ScheduleTable.schRepeatDate]!!.substring(5, 10)
                    else
                        ""
                    if ("1" == type) {
                        comename_tv.text = "每天重复 $repeatDate"
                        color = "0"
                    } else if ("2" == type) {
                        comename_tv.text = "每周重复 " + repeatDate
                        color = sharedPrefUtil!!.getString(context, ShareFile.USERFILE, ShareFile.WEEKCOLOR1, "4")
                    } else if ("3" == type) {
                        comename_tv.text = "每月重复 " + repeatDate
                        color = sharedPrefUtil!!.getString(context, ShareFile.USERFILE, ShareFile.MONTHCOLOR2, "3")
                    } else if ("4" == type || "6" == type) {
                        comename_tv.text = "每年重复 " + repeatDate
                        color = sharedPrefUtil!!.getString(context, ShareFile.USERFILE, ShareFile.YEARCOLOR3, "2")
                    } else if ("5" == type) {
                        comename_tv.text = "工作日重复 " + repeatDate
                        color = "0"
                    } else {
                        App.getDBcApplication().deleteScheduleData(mMap[ScheduleTable.schID])
                    }
                    if ("1" == important) {
                        important_icon.visibility = View.VISIBLE
                        important_icon.background = context.resources.getDrawable(R.mipmap.icon_zhongyao)
                    } else {
                        important_icon.visibility = View.GONE
                    }
                    setBGcolor(timeall_rela_right, color)
                } else {
                    comename_tv.visibility = View.GONE
                }
            }

            if ("2" == mMap[ScheduleTable.schSourceType]) {
                timeall_tv_content.text = if (schContentschRemark12.length > 2 && schContentschRemark12.substring(0, 2) == "#%")
                    schContentschRemark12.substring(2, schContentschRemark12.length)
                else
                    schContentschRemark12
                val list = App.getDBcApplication().getCalenderNoteDetailData(userid, mMap[ScheduleTable.schSourceDesc], false)

                val nums: String

                if (list.size > 0) {
                    nums = when {
                        list[0].style == 0 -> {
                            val endstate = list.count { it.endstate == 1 }
                            "(" + endstate + "/" + list.size + ")"
                        }
                        list[0].style == 4 -> "(" + nums(list[0].style, list) + ")"
                        else -> "(" + list.size + ")"
                    }

                    val style1 = SpannableStringBuilder(nums)
                    style1.setSpan(ForegroundColorSpan(context.resources.getColor(R.color.gongkai_txt)), 0, nums.length,
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) //设置指定位置文字的颜色

                    val map = App.getDBcApplication().QueryhongFuData(mMap[ScheduleTable.schRepeatID])
                    if (map != null) {
                        if (map[CLRepeatTable.repContent]!!.length > 2 && map[CLRepeatTable.repContent]!!.substring(0, 2) == "#%") {
                            val list1 = App.getDBcApplication().getCalenderNoteDetailData(userid, map[CLRepeatTable.repSourceDesc], false)
                            if (list1.size >= 1 && UriUtils.isUrl(list1[0].contents)) {
                                xcx_tv.visibility = View.VISIBLE
                            } else {
                                timeall_tv_content.append(style1)
                            }
                        } else {
                            timeall_tv_content.append(style1)
                        }
                    } else if (schContentschRemark12.length > 2 && schContentschRemark12.substring(0, 2) == "#%") run {
                        val list = App.getDBcApplication().getCalenderNoteDetailData(userid, mMap[ScheduleTable.schSourceDesc], false)
                        if (list.size >= 1 && UriUtils.isUrl(list[0].contents)) {
                            xcx_tv.visibility = View.VISIBLE
                        } else {
                            timeall_tv_content.append(style1)
                        }
                    } else {
                        timeall_tv_content.append(style1)
                    }

                    if ("1" == isEnd) {
                        val style = SpannableStringBuilder(timeall_tv_content.text.toString())
                        style.setSpan(ForegroundColorSpan(context.resources.getColor(R.color.endtextcolor)), 0, timeall_tv_content.text.length,
                                Spannable.SPAN_EXCLUSIVE_INCLUSIVE) //设置指定位置文字的颜色
                        timeall_tv_content.text = style
                    }
                }
            } else if ("3" == mMap[ScheduleTable.schSourceType] || "4" == mMap[ScheduleTable.schSourceType] || "5" == mMap[ScheduleTable.schSourceType]) {
                timeall_tv_content.text = if (schContentschRemark12.length > 2 && schContentschRemark12.substring(0, 2) == "#%")
                    schContentschRemark12.substring(2, schContentschRemark12.length)
                else
                    schContentschRemark12
                if ("3" == mMap[ScheduleTable.schSourceType]) {
                    timeall_tv_content.setTextColor(context.resources.getColor(R.color.Saturdaybackcolor))
                } else {
                    timeall_tv_content.setTextColor(context.resources.getColor(R.color.blue))
                }

                var nums = App.getDBcApplication().getCalenderNoteData(mMap[ScheduleTable.schSourceDesc])
                nums = if (nums != "0" && !nums.isEmpty()) {
                    "($nums)"
                } else {
                    ""
                }
                val style1 = SpannableStringBuilder(nums)
                style1.setSpan(ForegroundColorSpan(context.resources.getColor(R.color.gongkai_txt)), 0, nums.length,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) //设置指定位置文字的颜色
                timeall_tv_content.append(style1)
                if (mMap[ScheduleTable.schcRecommendName]!!.isNotEmpty() && mMap[ScheduleTable.schcRecommendId]!!.isNotEmpty()) {
                    comename_tv.visibility = View.VISIBLE
                    comename_tv.text = "@" + mMap[ScheduleTable.schcRecommendName]
                }
                comename_tv.setTextColor(context.resources.getColor(R.color.gongkai_txt))

                if (isEnd == "1") {
                    timeall_tv_content.setTextColor(Color.parseColor(colorState))
                    timeall_tv_time.setTextColor(Color.parseColor(colorState))
                    bottom_month.setTextColor(Color.parseColor(colorState))
                    bottom_week.setTextColor(Color.parseColor(colorState))
                    timeall_tv_content.paint.flags = Paint.STRIKE_THRU_TEXT_FLAG or Paint.ANTI_ALIAS_FLAG
                }
            }
            if (Integer.valueOf(mMap[ScheduleTable.schcRecommendId]) < 0 && mMap[ScheduleTable.schcRecommendName]!!.isEmpty()) {
                comename_tv.visibility = View.VISIBLE
                comename_tv.text = "到期日"
            }
            if (Integer.valueOf(mMap[ScheduleTable.schcRecommendId]) == -2) {
                comename_tv.visibility = View.VISIBLE
                comename_tv.text = "来自网页输入"
                comename_tv.setTextColor(Color.parseColor("#aaaaaa"))
            }
        }

        if ("3" == isEnd && "1" == mMap[ScheduleTable.schRead]) {
            if (Integer.valueOf(list[holder.adapterPosition][ScheduleTable.schcRecommendId]) > 0 && Integer.valueOf(list[holder.adapterPosition][ScheduleTable.schAID]) == 0) {
                new_img.background = context.resources.getDrawable(R.mipmap.icon_diandian)
                new_img.visibility = View.VISIBLE
                timeall_tv_lastday.visibility = View.GONE
                guoqi_img.visibility = View.GONE
                newcome_ll.visibility = View.GONE
                comename_tv.visibility = View.GONE
            }
        } else if ("0" == isEnd && "1" == mMap[ScheduleTable.schRead]) {
            if (Integer.valueOf(list[holder.adapterPosition][ScheduleTable.schcRecommendId]) > 0 && Integer.valueOf(list[holder.adapterPosition][ScheduleTable.schAID]) == 0) {
                timeall_tv_lastday.visibility = View.GONE
                guoqi_img.visibility = View.VISIBLE
                newcome_ll.visibility = View.GONE
                comename_tv.visibility = View.GONE
            }

        } else if ("2" == isEnd && "1" == mMap[ScheduleTable.schRead]) {
            if (Integer.valueOf(list[holder.adapterPosition][ScheduleTable.schcRecommendId]) > 0 && Integer.valueOf(list[holder.adapterPosition][ScheduleTable.schAID]) == 0) {
                new_img.background = context.resources.getDrawable(R.mipmap.icon_diandian)
                new_img.visibility = View.VISIBLE
                timeall_tv_lastday.visibility = View.GONE
                guoqi_img.visibility = View.GONE
                newcome_ll.visibility = View.GONE
                comename_tv.visibility = View.GONE
            }
        } else {
            if (Integer.valueOf(list[holder.adapterPosition][ScheduleTable.schcRecommendId]) <= 0 && Integer.valueOf(list[holder.adapterPosition][ScheduleTable.schAID]) != 0) {
                new_img.visibility = View.GONE
            }
            newcome_ll.visibility = View.GONE
            newcome_tv.visibility = View.GONE
        }

        if (Integer.valueOf(list[holder.adapterPosition][ScheduleTable.schpisEnd]) == 1) {
            timeall_tv_content.setTextColor(Color.parseColor("#7F7F7F"))
            timeall_tv_time.setTextColor(Color.parseColor("#7F7F7F"))
            bottom_month.setTextColor(Color.parseColor("#7F7F7F"))
            bottom_week.setTextColor(Color.parseColor("#7F7F7F"))
            select_cb.isChecked = true
            timeall_rela_right.background = context.resources.getDrawable(R.drawable.bg_sch_end)
            timeall_tv_content.paint.flags = Paint.STRIKE_THRU_TEXT_FLAG or Paint.ANTI_ALIAS_FLAG
        }

        if (mMap[ScheduleTable.schcRecommendName]!!.isNotEmpty() && mMap[ScheduleTable.schcRecommendId]!!.isNotEmpty()) {
            comename_tv.visibility = View.VISIBLE
            comename_tv.text = "@" + mMap[ScheduleTable.schcRecommendName]
        }

        xcx_tv.visibility = View.GONE
        if ("0" != list[holder.adapterPosition][ScheduleTable.schRepeatID]) {
            val map = App.getDBcApplication().QueryhongFuData(list[holder.adapterPosition][ScheduleTable.schRepeatID])
            if (map != null) {
                val bean = App.getDBcApplication().get_tb_function_my(map[CLRepeatTable.remark2])
                if (bean != null && bean.url.isNotEmpty()) {
                    xcx_tv.visibility = View.VISIBLE
                } else if (map[CLRepeatTable.repContent]!!.length > 2 && map[CLRepeatTable.repContent]!!.substring(0, 2) == "#%") run {
                    val list = App.getDBcApplication().getCalenderNoteDetailData(userid, map[CLRepeatTable.repSourceDesc], false)
                    if (list.size >= 1 && UriUtils.isUrl(list[0].contents)) {
                        xcx_tv.visibility = View.VISIBLE
                    }
                } else {
                    xcx_tv.visibility = View.GONE
                }
            }
        } else if (schContentschRemark12.length > 2 && schContentschRemark12.substring(0, 2) == "#%") run {
            val list = App.getDBcApplication().getCalenderNoteDetailData(userid, mMap[ScheduleTable.schSourceDesc], false)
            if (list.size >= 1 && UriUtils.isUrl(list[0].contents)) {
                xcx_tv.visibility = View.VISIBLE
            } else {
                xcx_tv.visibility = View.GONE
            }
        } else {
            if ("" != mMap[ScheduleTable.schRemark6]) {
                val bean = App.getDBcApplication().get_tb_function_my(mMap[ScheduleTable.schRemark6])
                if (bean != null && bean.url.isNotEmpty()) {
                    xcx_tv.visibility = View.VISIBLE
                } else {
                    xcx_tv.visibility = View.GONE
                }
            }
        }
        if (isEnd != "1") {
            val style = SpannableStringBuilder(if (schContentschRemark12.length > 2 && schContentschRemark12.substring(0, 2) == "#%")
                schContentschRemark12.substring(2, schContentschRemark12.length)
            else
                schContentschRemark12)
            var remark11 = list[holder.adapterPosition][ScheduleTable.schRemark11]
            if (remark11 == "" || remark11 == null) {
                remark11 = "0"
            }
            val color = Integer.valueOf(remark11)
            if (color > 0) {
                style.setSpan(BackgroundColorSpan(context.resources.getColor(colorss[color])), 0, (if (schContentschRemark12.length > 2 && schContentschRemark12.substring(0, 2) == "#%")
                    schContentschRemark12.substring(2, schContentschRemark12.length)
                else
                    schContentschRemark12).length,
                        Spannable.SPAN_EXCLUSIVE_INCLUSIVE)
                if (color > 2) {
                    style.setSpan(ForegroundColorSpan(Color.WHITE), 0, (if (schContentschRemark12.length > 2 && schContentschRemark12.substring(0, 2) == "#%")
                        schContentschRemark12.substring(2, schContentschRemark12.length)
                    else
                        schContentschRemark12).length,
                            Spannable.SPAN_EXCLUSIVE_INCLUSIVE)
                }
                timeall_tv_content.text = style
                timeall_tv_content.setLineSpacing(1f, 1f)
            }

        }
        if (sharedPrefUtil!!.getString(context, ShareFile.USERFILE, ShareFile.TYPEUID, "").isNotEmpty()) {
            holder.itemView.sch_sl.setScroll(false)
            select_cb.isClickable = false
        } else {
            select_cb.isClickable = true
        }

        if ("1" == mMap[ScheduleTable.schRemark1] && mMap[ScheduleTable.schRemark5] != null && mMap[ScheduleTable.schRemark5]!!.isNotEmpty()) {
            comename_tv.text = "To:${mMap[ScheduleTable.schRemark5]}"
            comename_tv.visibility = View.VISIBLE
        }
    }

    private var colorss = intArrayOf(R.color.white, R.color.color_m_1, R.color.color_m_2, R.color.color_m_3, R.color.color_m_4, R.color.color_m_5)

    fun nums(stylee: Int, list: List<CalenderNoteBean.PageBean.ItemsBean>): String {
        var tick1 = 0
        var tick2 = 0
        for (listBean in list) {
            if (listBean.endstate == 1) {
                tick1 += 1
            }
            if (listBean.endstate == 2) {
                tick2 += 1
            }
        }
        val title_new = if (stylee == 0) {
            if (list.isEmpty()) {
                "0"
            } else {
                tick1.toString() + "/" + list.size
            }
        } else if (stylee == 4) {
            if (list.isEmpty()) {
                "0"
            } else {
                tick1.toString() + "/" + tick2 + "/" + list.size
            }
        } else {
            list.size.toString() + ""
        }

        return title_new
    }

    internal var color = "0"
    internal fun setBGcolor(linearLayout: LinearLayout, type: String) {
        when (type) {
            "1" -> linearLayout.background = context.resources.getDrawable(R.drawable.repeat_bg_color1)
            "2" -> linearLayout.background = context.resources.getDrawable(R.drawable.repeat_bg_color2)
            "3" -> linearLayout.background = context.resources.getDrawable(R.drawable.repeat_bg_color3)
            "4" -> linearLayout.background = context.resources.getDrawable(R.drawable.repeat_bg_color4)
            "0" -> linearLayout.background = context.resources.getDrawable(R.drawable.repeat_bg_color1)
        }
    }


}